package root.item;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;


public class Category implements CategoryInterface {
	
	private static Collection<String> TAGS_EXISTENTES = new HashSet<String>(); 
	private Collection<String> tags;
	
	public Category(String category) {
		setCategory(category);
	}
	
	/**
	 * Setter das categorias (tags)
	 * @param String category : string contendo as tags a serem atribuidas
	 */
	public void setCategory(String category) {
		instantiateList();
		String[] list = category.split(", ");
		for(String c : list)
			addTag(c);
	}

	/**
	 * Indica a presenca da tag do parametro
	 * @param String tag
	 */
	public boolean hasTag(String tag) {
		return tags.contains(tag);
	}
	
	public static boolean existTag(String tag){
		return TAGS_EXISTENTES.contains(tag);
	}
	
	@Override
	public String toString() {
		String text = tags.toString();
		return text.substring(1, text.length()-1);
	}
	private void instantiateList() {
		tags = new ArrayList<String>();
	}
	
	private void addTag(String c) {
		if(!hasTag(c))
			tags.add(c);
		TAGS_EXISTENTES.add(c);	
	}
	
}
